package cn.edu.scau.cmi.linhongyu.adapter;

import java.util.ArrayList;
import java.util.List;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;


public class AdapterController {

    @FXML
    private Button addStudent;

    @FXML
    private TextArea classArea;

    @FXML
    private Label id;

    @FXML
    private TextField idField;

    @FXML
    private Label name;

    @FXML
    private TextField nameField;

    @FXML
    private Label object;

    @FXML
    private TextArea objectArea;

    List<Student> studentList1 = new ArrayList<Student>();
	List<Student> studentList2 = new ArrayList<Student>();
	@FXML
    void onClick(ActionEvent event) {
    	int studentId = Integer.valueOf(idField.getText());
    	String studentName = nameField.getText();
    	adapterOfClass(studentId,studentName);
    	adapterOfObject(studentId,studentName);
    }
    
	void adapterOfClass(int studentId, String studentName) {
    	Student student = new Student(studentId,studentName);
    	studentList1.add(student);
    	Target adapterOfClass = new AdapterOfClass();
    	List<Student> sortedList = adapterOfClass.sort(studentList1);
    	String text="学号:"+"     "+"姓名:\n";
    	for(int i=0;i<sortedList.size();i++) {
    		
    		text = text +String.valueOf(sortedList.get(i).getId())+"          "+sortedList.get(i).getName()+"\n";
    	}
    	classArea.setText(text);
    }

    void adapterOfObject(int studentId, String studentName) {
    	Student student = new Student(studentId,studentName);
    	studentList2.add(student);
    	Target adapterOfObject = new AdapterOfObject();
    	List<Student> sortedList = adapterOfObject.sort(studentList2);
    	String text="学号:"+"     "+"姓名:\n";
    	for(int i=0;i<sortedList.size();i++) {
    		
    		text = text +String.valueOf(sortedList.get(i).getId())+"          "+sortedList.get(i).getName()+"\n";
    	}
    	objectArea.setText(text);
    }


}
